package 力扣日常刷题.木22一月.第18天0130;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author 帅小伙
 * @date 2022/1/30
 * @description
 */
public class Demo35两句话中的不常见单词 {


    public String[] uncommonFromSentences(String s1, String s2) {
        HashMap<String, Integer> map1 = new HashMap<>();
        HashMap<String, Integer> map2 = new HashMap<>();

        for (String s : s1.split(" ")) {
            map1.put(s, map1.getOrDefault(s,0)+1);
        }
        for (String s : s2.split(" ")) {
            map2.put(s, map2.getOrDefault(s,0)+1);
        }
        ArrayList<String> list = new ArrayList<>();

        for (String s : map1.keySet()) {
            if(map1.get(s) == 1 && !map2.containsKey(s))list.add(s);
        }

        for (String s : map2.keySet()) {
            if(map2.get(s) == 1 && !map1.containsKey(s))list.add(s);
        }
        String[] ans = new String[list.size()];
        for (int i = 0; i < list.size(); i++) ans[i] = list.get(i);
        return ans;

    }
}
